package org.argus.common.web.core.config;

import org.argus.common.core.json.LongToStringObjectMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 通用WEB配置
 * @Author 刘文/Cliff Liu
 * @Date 2024/5/14
 */
@Configuration
@EnableFeignClients(basePackages = "org.argus")
public class CommonWebConfiguration implements WebMvcConfigurer {
    /**
     * 解决前端js处理大数字丢失精度问题，将Long和BigInteger转换成string
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
        MappingJackson2HttpMessageConverter  jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter ();
        jackson2HttpMessageConverter.setObjectMapper(new LongToStringObjectMapper());
        return jackson2HttpMessageConverter;
    }
}